﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Web;
using OrbitOne.Elmah.Data;
using OrbitOne.Elmah.Logic;
/*
using OrbitOne.Feed.Domain;
using OrbitOne.Feed.Interfaces;
*/
using System.Configuration;

namespace OrbitOne.Elmah.Presenter
{
/*    public class FilteredErrorFeedLoader : IWebFeedDataLoader
    {
        private static RSSFeedConfigurationSection _config = RSSFeedConfigurationSection.Load();

        public WebFeed DoLoad()
        {
            return GetErrorFeed();
        }

        private WebFeed GetErrorFeed()
        {
            int filterSequencialId;
            Int32.TryParse(HttpContext.Current.Request["fsid"], out filterSequencialId);

            ErrorSearchFilter filter =
                    HttpContext.Current.Profile.GetProfileGroup("SearchFilters").GetPropertyValue(
                            string.Format("SearchFilter{0}", filterSequencialId)) as ErrorSearchFilter;

            string feedTitle = string.Format("{0} - {1}", HttpContext.Current.User.Identity.Name, filter.Name);
            string errorSearchPageUrl = string.Format("{0}?fsid={1}", _config.ErrorSearchPageurl, filterSequencialId);
            WebFeed webFeed = new WebFeed(CultureInfo.InvariantCulture, feedTitle,
                                          DateTime.Now.ToUniversalTime(), new Uri(errorSearchPageUrl), "");

            webFeed.Author = new Author(_config.SenderName, _config.SenderEmail);
            webFeed.Copyright = string.Format("© {0}", _config.CompanyName);
           
//            foreach (SearchRecord sr in GetErrors(filter))
//            {
//                foreach (var error in sr.Errors)
//                {
//                    string title = string.Format("{0} ({1})", error.ApplicationName, error.HostName);
//                    string url = string.Format("{0}?id={1}", _config.ErrorDetailPageurl, error.Id);
//                    string content = string.Format("Error Level: {0}<br/>Error Type: {1}<br/> {2}", error.ErrorLevel, error.ErrorType, error.ErrorMessage);
//
//                    Topic topic = CreateTopic(title, error.HappeningTime, url,
//                                              content, error.ApplicationName, string.Empty, 1, MimeTypes.pdf, string.Empty);
//                    topic.Id = error.Id.ToString();
//                    webFeed.Topics.Add(topic);    
//                }
//            }
            webFeed.Topics.Add(new Topic(new Guid("3C3654C9-3EA7-40B1-BAFF-7B5ADE06C33B"),"title",DateTime.Now,"desc",new Uri("http://google")));
            webFeed.Topics.Add(new Topic(new Guid("327DEB08-1ED7-41BA-B4D7-ADE4F09B1002"),"title",DateTime.Now,"desc",new Uri("http://google")));
            webFeed.Topics.Add(new Topic(new Guid("27C9981E-C3C8-46FB-817E-DD72927ED50B"),"title",DateTime.Now,"desc",new Uri("http://google")));
            webFeed.Topics.Add(new Topic(new Guid("E97BDE2A-5DE6-4B9E-848C-4CD22595305D"),"title",DateTime.Now,"desc",new Uri("http://google")));
            webFeed.Topics.Add(new Topic(new Guid("FA75835C-F95D-4F98-851E-68309A13C259"),"title",DateTime.Now,"desc",new Uri("http://google")));

            return webFeed;

        }
        private IList<SearchRecord> GetErrors(ErrorSearchFilter filter)
        {
            var errorService = new OrbitOneElmahErrorService();
            var errors = errorService.SearchErrors(filter, 0, 20);

            return errors.SearchRecords;
        }

        private Topic CreateTopic(
                string title,
                DateTime time,
                string url,
                string description,
                string category,
                string contentUri,
                long contentLength,
                string contentMimetype,
                string iconUrl)
        {
            var topicUri = new Uri(url, UriKind.Absolute);
            var cat = new Category(category);
            var topic = new Topic(HttpUtility.HtmlDecode(title), time, HttpUtility.HtmlDecode(description), topicUri);

            topic.Categories.Add(cat);

            if (iconUrl != string.Empty) topic.Icon = new Uri(iconUrl);
            if (contentUri != string.Empty) topic.Content = new Content(new Uri(contentUri), contentLength, contentMimetype);

            return topic;
        }




    }*/
}